#!/bin/bash

process_files() {
    local title="$1"
    local output_file="$2"
    local file_path="$3"
    local executable="$4"
    local test_params="$5"

    echo "" >> "${output_file}"
    echo "=============================== ${title} ===============================" >> "${output_file}"

    find "${file_path}" -type f -name "*.txt" | sort | while read -r file; do
        echo "" >> "${output_file}"
        echo "----- ${file} -----" >> "${output_file}"

        echo ">>> SOURCE:" >> "${output_file}"
        cat "${file}" >> "${output_file}"

        echo "<<< RESULT:" >> "${output_file}"
        "${executable}" "${file}" "${test_params}" >> "${output_file}"
    done
}


OUTPUT_FILE="test/tmp/test-lsp-client.out"
BASE_DIR="test/source/lsp/client"
EXECUTABLE="build/tests/test-lsp-client"

echo "Тесты языкового клиента" > ${OUTPUT_FILE}


process_files "Тесты языкового клиента (json)" \
    "${OUTPUT_FILE}" \
    "${BASE_DIR}/json" \
    "${EXECUTABLE}" \
    "data/servers/lsp/bin/simodo-lsp-json test/tmp/server.log Debug save"


process_files "Тесты языкового клиента (simodo)" \
    "${OUTPUT_FILE}" \
    "${BASE_DIR}/simodo" \
    "${EXECUTABLE}" \
    "data/servers/lsp/bin/simodo-lsp bin/semantics bin/modules data/grammar test/tmp/server.log Debug save"

exit 0
